<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=returnVisit-width, initial-scale=1, maximum-scale=1">
    <% include("/templates/common/header.html"){} %>
    <!-- jqgrid-->
    <link href="${ctxPath!}/css/bootstrap.css?v=3.3.6" rel="stylesheet">
    <link href="${ctxPath!}/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="${ctxPath!}/jqgrid/jqgrid.css" rel="stylesheet">
    <style>
        .ui-jqgrid-btable tbody tr td{
            vertical-align: middle!important;
        }
    </style>
</head>
<body>
<div class="content-search">
    <form id="search" class="layui-form layui-form-pane" lay-filter="form">
        <div class="layui-inline" style="margin-left: 10px;">
            <div class="layui-inline" style="margin-left: 10px;">
                <div class="layui-input-inline">
                    <select name="rid" id="rid" lay-filter="rid">
                        <option value="">请选择回访对象</option>
                        <option value="4">育婴师</option>
                        <option value="7">用户</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <atom:auth type="button" perm="sys:returnVisit:add" iconText="&#xe654;" onclick="return add();" text="添加回访记录"/>
            </div>
        </div>
    </form>
</div>
<!-- 内容主体区域 -->
<div style="padding: 2px;">
    <div class="jqGrid_wrapper">
        <table id="table"></table>
        <div id="pager" ></div>
    </div>
</div>
</div>
<script src="${ctxPath!}/jquery/jquery.min.js?v=2.2.4"></script>
<script src="${ctxPath!}/jquery/jquery.form.js?v=3.50.0"></script>
<script src="${ctxPath!}/jqgrid/i18n/grid.locale-cnffe4.js?0820"></script>
<script src="${ctxPath!}/jqgrid/jquery.jqGrid.minffe4.js?0820"></script>
<script src="${ctxPath!}/jqgrid/frozen.js?v=1.0.1"></script>
<script src="${ctxPath!}/jqgrid/myjqGrid.js"></script>
<script src="${ctxPath!}/layui/layui.js"></script>
<script>

    layui.use('form', function(){
    });

    var colNames = ["被回访人姓名","回访时间","回访内容","操作"];
    var colModel = [{
        name : "username",
        index : "username",
        sortable : false,
        editable : false,
        width : 80,
        align : "center"
    },{
        name : "visitDate",
        index : "visitDate",
        sortable : false,
        editable : false,
        width : 100,
        align : "center",
        formatter:'date',formatoptions: {newformat:'Y-m-d'}
    },{
        name : "content",
        index : "content",
        sortable : false,
        editable : false,
        width : 180,
        align : "center"
    },
        {
            name: "action",
            index: "action",
            width: 150,
            title: false,
            editable: true,
            align: "center",
            formatter: function (cellvalue, options, rowdata) {
                var html = "";
                html +=
                    '<atom:auth type="button" perm="sys:returnVisit:edit" extClass="btn-edit" iconText="&#xe642;" dataId="' + rowdata.id + '" text="编辑回访记录" />' +
                    '<atom:auth type="button" perm="sys:returnVisit:delete" extClass="btn-del layui-bg-red" iconText="&#xe640;" dataId="' + rowdata.id + '" text="删除回访记录" />';
                return html;
            }
        }];

    var myJqGrid = null;
    $(document).ready(function () {
        myJqGrid = new MyJqGrid({
            jqGrid_id: 'table',
            data: "${ctxPath!}/sys/returnVisit/list.json",
            isSubGrid: false,
            autowidth: true,
            shrinkToFit: true,
            autoScroll: true,
            colNames: colNames,
            colModel: colModel
        })
    });


    function search(){
        myJqGrid.reloadGrid({'rid':$("#rid").val()});
        return false;
    }

    function add() {
        layer.open({
            title: '添加回访记录',
            type: 2,
            area: ['500px', '450px'],
            content: '${ctxPath!}/sys/returnVisit/edit?rid='+$("#rid").val()
        });
        return false;
    }

    $(function(){

        $(document).on("click", ".btn-edit", function (e) {
            layer.open({
                title: '编辑回访记录',
                type: 2,
                area: ['550px', '470px'],
                content: '${ctxPath!}/sys/returnVisit/edit?id='+$(this).data("id")
            });
        });

        $(document).on("click", ".btn-del", function (e) {
            var id = $(this).data("id");
            layer.confirm('确定删除该回访记录吗？', {
                icon: 3,
                btn: ['确定','取消'] //按钮
            }, function(){ //确定
                var params = {"id":id};
                console.log(id);
                $.post("${ctxPath!}/sys/returnVisit/delete", params, function(data){
                    if(data.status == 200){
                        layer.alert(data.msg, {
                            icon: 1,
                            skin: 'layer-ext-moon'
                        },function () {
                            search();
                            layer.closeAll();
                        });
                    }else{
                        layer.alert(data.msg, {
                            icon: 2,
                            skin: 'layer-ext-moon'
                        });
                    }
                });
            }, function(){ //取消
            });
        });

    });

</script>
</body>
</html>